package se.lnu.axez.widgets;

import se.lnu.axez.AxezContext;
import se.lnu.axez.IVisual;
import se.lnu.axez.TriMesh;
import se.lnu.axez.shaders.FragmentShader;
import se.lnu.axez.shaders.ShaderManager;
import se.lnu.axez.shaders.ShaderProgram;
import se.lnu.axez.shaders.SimpleFragmentShader;
import se.lnu.axez.shaders.SimpleTextureFragmentShader;
import se.lnu.axez.shaders.SimpleTextureVertexShader;
import se.lnu.axez.shaders.SimpleVertexShader;
import se.lnu.axez.shaders.VertexShader;
import se.lnu.axez.textures.CheckersTexture;
import se.lnu.axez.textures.ITexture;

final class ButtonVisual implements IVisual {
//	private final Class<? extends TriMesh> meshType;
	private final int meshId;
	private TriMesh triMesh;
	private ITexture texture;
	private ShaderProgram shaderProgram;

	public ButtonVisual(int meshResourceId) {
		this.meshId = meshResourceId;
	}

//	public ButtonVisual(Class<? extends TriMesh> meshType) {
//		if (meshType == null) {
//			throw new IllegalArgumentException("meshType cannot be null");
//		}
//		
//		this.meshType = meshType;
//	}
//	
	public void init(AxezContext context) {
		this.triMesh = context.getTriMeshManager().getTriMesh(this.meshId);
		this.texture = context.getTextureManager().getTexture(CheckersTexture.class);
		final ShaderManager shaderManager = context.getShaderManager();
		final VertexShader vs = shaderManager.getVertexShader(SimpleVertexShader.class);
		final FragmentShader fs = shaderManager.getFragmentShader(SimpleFragmentShader.class);
		this.shaderProgram = shaderManager.getShaderProgram(vs, fs);
	}

	public void draw(AxezContext context) {
		this.shaderProgram.use(context);
//		this.texture.use(this.shaderProgram);
		this.triMesh.draw(this.shaderProgram);
	}
}
